/**
 * 权限控制指令
 * <some-element v-clearreadonly></some-element>
 */
function dealWithReadonly(el, binding, vnode) {
    if (el.children[0].children[0]) {
        if (!vnode.componentInstance.filterable) {
            el.children[0].children[0].setAttribute('disabled', true)
        }
        clearReadOnlyMounted()
        el.children[0].children[0].onblur = function() {
            let _this = this
            setTimeout(() => {
                if (_this.getAttribute('readonly')) {
                    _this.removeAttribute('readonly')
                }
            }, 60)
        }
        el.children[0].children[0].onclick = function() {
            let _this = this
            if (_this.getAttribute('readonly')) {
                _this.removeAttribute('readonly')
            }
        } 
    }
}
function clearReadOnlyMounted() {
    if (document.getElementsByClassName('el-select')) {
        Array.from(document.getElementsByClassName('el-select')).forEach(item => {
            if (item.children[0].children[0] && item.children[0].children[0].getAttribute('readonly')) {
                item.children[0].children[0].removeAttribute('readonly')
            }
        })
    }
}
export default {
    bind: function(el, binding, vnode) {
        dealWithReadonly(el, binding, vnode)  
    },
    inserted: function(el, binding, vnode) {
        dealWithReadonly(el, binding, vnode)  
    },
    update: function(el, binding, vnode) {
        dealWithReadonly(el, binding, vnode)
    }
}